package com.marry.producer.service;

import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;



/**
 * @author ml
 * @create 2017-08-03--14:18
 */
@Service
public class EmailServiceImpl implements EmailService {

    private static final Logger logger= LoggerFactory.getLogger(EmailServiceImpl.class);

    @Autowired()
    @Qualifier(value = "rabbitTemplate")
    private RabbitTemplate rabbitTemplate;


    @Value("${mq.exchange}")
    private String exchange;

    @Value("${mq.routekey}")
    private String routeKey;


    @Override
    public void sendEmail(String message) throws Exception {


        try {
            rabbitTemplate.convertAndSend(exchange,routeKey,message);
        } catch (AmqpException e) {
            e.printStackTrace();
            logger.error("EmailServiceImpl.sendEmail", ExceptionUtils.getMessage(e));
        }

    }
}
